<template>
  <div class='addProject-container'>
    <el-row>
      <el-col :span="24">
        <!-- <div class="project-title">添加项目</div> -->
      </el-col>
      <el-col class="pro-form">
        <el-form :model="projectInfoForm"
                 v-if="projectStep===1"
                 status-icon
                 :rules="rules"
                 ref="projectInfoForm"
                 label-width="190px"
                 class="demo-projectInfoForm">
          <!-- :disabled="status==='detail'" -->
          <el-form-item label="是否工业化项目"
                        prop="is_indust_project">
            <el-radio-group @change="toggleIsPlat"
                            :disabled="status==='detail'||isIndustryPro==true"
                            v-model="projectInfoForm.is_indust_project">
              <el-radio label="1">是</el-radio>
              <el-radio label="2">否</el-radio>
            </el-radio-group>
          </el-form-item>

          <!-- 基础项目信息 -->
          <div class="base-project-info">
            <el-form-item label="项目代码"
                          :prop="isIndustryPro==true?'project_code':''">
              <el-tooltip class="item"
                          effect="dark"
                          content="点击当前页面的任意空白处(失去焦点),判断当前项目编码是否已经存在"
                          placement="top">
                <el-input v-model="projectInfoForm.project_code"
                          :disabled="status=='detail'"
                          class="normal-input"
                          @blur="onProCodeKeyUp(projectInfoForm.project_code)"
                          placeholder="请输入项目代码"></el-input>
              </el-tooltip>
              <el-tooltip class="item"
                          effect="dark"
                          :disabled="status==='detail'"
                          content="注:项目代码应采用浙江政务服务网投资项目在线审批监管平台
                          (工程建设项目全流程审批管理系统)规定的项目代码"
                          placement="right">
                <el-button icon="el-icon-question"
                           :disabled="status==='detail'"
                           type="text"></el-button>
              </el-tooltip>
            </el-form-item>
            <el-form-item label="项目名称"
                          prop="project_name">
              <div class="pro-name-style">
                <el-input class="normal-input"
                          :disabled="status==='detail'"
                          placeholder="请输入项目名称"
                          v-model="projectInfoForm.project_name"></el-input>
                <div v-if="projectInfoForm.is_indust_project==1"
                     class="bind-project">
                  <el-button type="primary"
                             @click="onSyncZheLiIndPro">获取浙里建项目数据</el-button>
                </div>
                <div v-auth="'bind-project'"
                     class="bind-project">
                  <!-- 未绑定项目时 -->
                  <el-button @click="bindOuterProjectDialog"
                             v-if="projectInfoForm.jt_project_id===0 && projectStatus!=='detail'"
                             type="primary">绑定建投项目数据</el-button>
                  <!-- 已绑定项目时 -->
                  <el-tooltip v-if="projectInfoForm.jt_project_id!==0 && projectStatus!=='detail'"
                              effect="dark"
                              :content="`已绑定项目：${projectInfoForm.jt_project_name}`"
                              placement="top">
                    <el-button @click="bindOuterProjectDialog"
                               type="primary">绑定建投项目数据</el-button>
                  </el-tooltip>
                  <!-- 已绑定项目且处于详情页时 -->
                  <el-button type="text"
                             :disabled="status==='detail'"
                             v-if="projectInfoForm.jt_project_id!==0 && projectStatus==='detail'">
                    {{'已绑定项目：'+projectInfoForm.jt_project_name}}
                  </el-button>
                </div>
              </div>
            </el-form-item>
            <el-form-item label="项目简称"
                          prop="nick_name">
              <el-input class="normal-input"
                        placeholder="请输入项目简称"
                        :disabled="status==='detail'"
                        v-model="projectInfoForm.nick_name"></el-input>
              <el-tooltip class="item"
                          effect="dark"
                          :disabled="status==='detail'"
                          content="项目简称，方便手机显示项目名称"
                          placement="right">
                <el-button icon="el-icon-question"
                           :disabled="status==='detail'"
                           type="text"></el-button>
              </el-tooltip>
            </el-form-item>
            <el-form-item label="项目二维码"
                          v-show="status==='detail'">
              <div class="pro-code-style">
                <div id="qrcode"></div>
                <el-button @click="downLoad"
                           size="medium"
                           type="success"
                           class="imm-down">立即下载</el-button>
              </div>
            </el-form-item>
            <el-form-item label="部门邀请码"
                          v-show="status==='detail'">
              <el-input v-model="projectInfoForm.invite_code"
                        class="normal-input"
                        :disabled="status==='detail'"></el-input>
            </el-form-item>
            <el-form-item label="部门二维码"
                          v-show="status==='detail'">
              <div class="div-qrcode">
                <img class="depart-level-qrcode"
                     :src="qrcodeUrl"
                     alt="">
                <el-button type="success"
                           class="depart-down"
                           @click="onDownQrcode">下载</el-button>
              </div>
            </el-form-item>
            <!-- v-if="isShowFormItem('building_type')" -->
            <el-form-item label="建筑类型"
                          prop="building_type">
              <el-select v-model="projectInfoForm.building_type"
                         class="normal-input"
                         :disabled="status==='detail'"
                         placeholder="选择建筑类型">
                <el-option v-for="item in buildingTypeList"
                           :key="item.value"
                           :label="item.name"
                           :value="item.value">
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="业务身份"
                          prop="business_type">
              <!-- multiple business_type_list -->
              <el-select v-model="projectInfoForm.business_type"
                         class="normal-input"
                         :disabled="status==='detail'"
                         placeholder="选择业务身份"
                         @change="chooseBusinessType">
                <el-option v-for="item in businessTypeList"
                           :key="item.value"
                           :label="item.name"
                           :value="item.value"
                           :disabled="item.content1===''">
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="项目经理"
                          prop="leader_name">
              <el-input placeholder="请输入项目经理"
                        :disabled="status==='detail'"
                        class="normal-input"
                        v-model="projectInfoForm.leader_name"></el-input>
              <!-- <el-select v-model="projectInfoForm.leader_id"
                       class="normal-input"
                       @focus="openLeaderDialog"
                       placeholder="请选择项目经理">
              <el-option v-for="item in  managerArr"
                         :key="item.key"
                         :label="item.label"
                         :value="item.value"></el-option>
            </el-select> -->
            </el-form-item>
            <el-form-item label="项目部"
                          prop="dept_no">
              <el-select v-model="projectInfoForm.dept_no"
                         class="normal-input"
                         :disabled="status==='detail'"
                         placeholder="请选择项目部门"
                         @focus="openManageDialog">
                <el-option v-for="item in deptArr"
                           :key="item.key"
                           :label="item.label"
                           :value="item.value"></el-option>
              </el-select>
            </el-form-item>
            <!-- <el-form-item label="专业类型"
                        prop="major_type"
                        required>
            <el-select v-model="projectInfoForm.major_type"
                       @change="chooseMajorType"
                       class="normal-input"
                       placeholder="专业类型">
              <el-option v-for="item in majorTypeList"
                         :key="item.value"
                         :label="item.name"
                         :value="item.value">
              </el-option>
            </el-select>
            <el-tooltip class="item"
                        effect="dark"
                        content="完成项目体系配置后进行操作"
                        placement="right">
              <el-button icon="el-icon-question"
                         type="text"></el-button>
            </el-tooltip>
          </el-form-item> -->
            <!-- <el-form-item v-if="isShowFormItem('license_number')"
                        label="项目许可编号"
                        prop="license_number"
                        required>
            <el-input v-model="projectInfoForm.license_number"
                      class="normal-input"
                      placeholder="请输入项目许可编号">
            </el-input>
          </el-form-item> -->
            <!-- <el-form-item v-if="isShowFormItem('assembly_rate')"
                        label="装配率"
                        prop="assembly_rate"
                        required>
            <el-input v-model="projectInfoForm.assembly_rate"
                      class="normal-input"
                      placeholder="请输入装配率">
            </el-input>
          </el-form-item> -->
            <!-- <el-form-item v-if="isShowFormItem('floorage')"
                        label="建筑面积"
                        prop="floorage"
                        required>
            <el-input class="normal-input"
                      placeholder="请输入建筑面积"
                      v-model="projectInfoForm.floorage"></el-input>
          </el-form-item> -->
            <!-- v-show="isShowFormItem('address')" -->
            <el-form-item label="项目地址"
                          prop="city_no">
              <LocationSelect class="normal-input"
                              ref="locationSelect"
                              :statusVal.sync="status"
                              :locaData.sync="projectInfoForm"></LocationSelect>
            </el-form-item>
            <!-- v-if="isShowFormItem('address')" -->
            <el-form-item label="详细地址"
                          prop="address">
              <el-input class="normal-input"
                        :disabled="status==='detail'"
                        placeholder="请输入详细地址"
                        v-model="projectInfoForm.address"></el-input>
            </el-form-item>
            <!-- v-if="isShowFormItem('address')" -->
            <!-- <el-form-item label="地图位置"
                        prop="lonlat"
                        required>
            <el-input class="normal-input"
                      @focus="selectMap"
                      readonly
                      :value="projectInfoForm.lonlat">
            </el-input>
          </el-form-item> -->
            <el-form-item label="地图位置"
                          prop="lonlat">
              <el-input class="normal-input"
                        @focus="selectNewMap"
                        :disabled="status==='detail'"
                        readonly
                        :value="projectInfoForm.lonlat">
              </el-input>
            </el-form-item>
            <!-- <el-form-item v-if="isShowFormItem('status')"
                        label="项目状态"
                        prop="status"
                        required>
            <el-select v-model="projectInfoForm.status"
                       placeholder="请选择项目状态">
              <el-option v-for="item in projectStatusList"
                         :key="item.code_id"
                         :label="item.name"
                         :value="item.value">
              </el-option>
            </el-select>
          </el-form-item> -->
            <!-- <el-form-item v-if="isShowFormItem('contract_total')"
                        label="合同总额"
                        prop="contract_total"
                        required>
            <el-input class="normal-input"
                      placeholder="请输入合同总额"
                      v-model="projectInfoForm.contract_total"></el-input>
          </el-form-item> -->
            <!-- <el-form-item v-if="isShowFormItem('sign_time')"
                        label="签订时间"
                        prop="sign_time"
                        required>
            <el-date-picker class="normal-input"
                            v-model="projectInfoForm.sign_time"
                            placeholder="请选择签订时间"
                            value-format="yyyy-MM-dd">
            </el-date-picker>
            <el-input class="normal-input"
                      placeholder="请选择签订时间"
                      v-model="projectInfoForm.sign_time"></el-input>
          </el-form-item> -->
            <!-- <el-form-item v-if="isShowFormItem('application')"
                        label="技术应用"
                        prop="application"
                        required>
            <el-input class="normal-input"
                      placeholder="请输入技术应用"
                      v-model="projectInfoForm.application"></el-input>
          </el-form-item> -->
            <!-- v-if="isShowFormItem('img')" -->
            <el-form-item label="项目许可证编号"
                          prop="project_license_no">
              <el-input v-model="projectInfoForm.project_license_no"
                        class="normal-input"
                        :disabled="status==='detail'"
                        placeholder="请输入项目许可证编号"></el-input>
            </el-form-item>
            <el-form-item label="项目效果图"
                          prop="">
              <el-upload class="avatar-uploader"
                         action=""
                         :disabled="status==='detail'"
                         :show-file-list="false"
                         :on-success="handleAvatarSuccess"
                         :before-upload="beforeAvatarUpload"
                         :http-request="uploadProjectImg">
                <img v-if="projectInfoForm.img"
                     :src="projectInfoForm.img"
                     class="avatar">
                <i v-else
                   class="el-icon-plus avatar-uploader-icon"></i>
              </el-upload>
            </el-form-item>
          </div>

        </el-form>
        <!-- 工业化项目额外信息 -->
        <div v-if="projectInfoForm.is_indust_project==='1' && projectStep===2"
             class="industry-project-info">
          <el-form label-width="190px"
                   :disabled="status==='detail'"
                   :rules="extFormRules"
                   ref="extForm"
                   :model="industryProjectInfo">
            <!-- <el-col :span="12">
              <el-form-item label="项目代码"
                            prop="project_license_no">
                <el-input v-model="industryProjectInfo.project_license_no"
                          class="normal-input"
                          placeholder="请输入项目代码"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="">
                <el-button type="primary">同步1369工业化项目</el-button>
              </el-form-item>
            </el-col>-->
            <el-col :span="12">
              <el-form-item label="施工工程名称"
                            prop="project_name">
                <el-input v-model="industryProjectInfo.project_name"
                          placeholder="请输入施工工程名称"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="建设性质"
                            prop="construct_nature">
                <el-select v-model="industryProjectInfo.construct_nature"
                           placeholder="请选择建设性质">
                  <el-option v-for="item in buildingPropertyCode"
                             :key="item.code_id"
                             :label="item.name"
                             :value="item.value">
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="项目类型"
                            prop="project_type">
                <el-select v-model="industryProjectInfo.project_type"
                           placeholder="请选择项目类型">
                  <el-option v-for="item in projectTypeCode"
                             :key="item.code_id"
                             :label="item.name"
                             :value="item.value">
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="项目投资性质"
                            prop="invest_nature">
                <el-select v-model="industryProjectInfo.invest_nature"
                           placeholder="请选择项目投资性质">
                  <el-option v-for="item in investPropertyCode"
                             :key="item.code_id"
                             :label="item.name"
                             :value="item.value">
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="审批机构级别"
                            prop="approval_auth_level">
                <el-select v-model="industryProjectInfo.approval_auth_level"
                           placeholder="请选择审批机构级别">
                  <el-option v-for="item in auditLevelCode"
                             :key="item.code_id"
                             :label="item.name"
                             :value="item.value">
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="总报价（万元）"
                            prop="totall_cost">
                <el-input v-model="industryProjectInfo.totall_cost"
                          placeholder="请输入总报价"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="项目所在街道"
                            prop="street_no">
                <el-select v-model="industryProjectInfo.street_no"
                           @change="chooseStreet"
                           placeholder="请选择项目所在街道">
                  <el-option v-for="item in streetList"
                             :key="item.area_id"
                             :label="item.street"
                             :value="item.street_no">
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="总投资（万元）"
                            prop="total_invest">
                <el-input v-model="industryProjectInfo.total_invest"
                          placeholder="请输入总投资"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="质监站"
                            prop="quality_sup_station">
                <el-input v-model="industryProjectInfo.quality_sup_station"
                          placeholder="请输入质监站"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="质量安全监督编号"
                            prop="quality_safe_sup_no">
                <el-input v-model="industryProjectInfo.quality_safe_sup_no"
                          placeholder="请输入质量安全监督编号"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="建设地点"
                            prop="address">
                <el-input v-model="industryProjectInfo.address"
                          placeholder="请输入建设地点"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="项目位置"
                            prop="project_station">
                <el-input v-model="industryProjectInfo.project_station"
                          placeholder="请输入项目位置"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="总建筑面积"
                            prop="total_build_area">
                <el-input v-model="industryProjectInfo.total_build_area"
                          placeholder="请输入总建筑面积">
                  <template slot="append">㎡</template>
                </el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="是否重点项目"
                            prop="is_important">
                <el-select v-model="industryProjectInfo.is_important"
                           placeholder="请选择是否重点项目">
                  <el-option label="是"
                             value="1"></el-option>
                  <el-option label="否"
                             value="0"></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="长度（米）"
                            prop="len">
                <el-input v-model="industryProjectInfo.len"
                          placeholder="请输入长度"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="视频安装状态"
                            prop="video_install_status">
                <el-select v-model="industryProjectInfo.video_install_status"
                           placeholder="请选择视频安装状态">
                  <el-option v-for="item in videoInstallCode"
                             :key="item.code_id"
                             :label="item.name"
                             :value="item.value">
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="跨度（米）"
                            prop="width">
                <el-input v-model="industryProjectInfo.width"
                          placeholder="请输入跨度"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="建设单位名称"
                            prop="build_company">
                <el-input v-model="industryProjectInfo.build_company"
                          placeholder="请输入建设单位名称"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="合同价格（万元）"
                            prop="contract_price">
                <el-input-number v-model="industryProjectInfo.contract_price"
                                 placeholder="请输入合同价格"></el-input-number>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="建设单位社会统一信用代码"
                            prop="build_credit_code">
                <el-input v-model="industryProjectInfo.build_credit_code"
                          placeholder="请输入建设单位社会统一信用代码"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="合同开工日期"
                            prop="contract_start_date">
                <el-date-picker v-model="industryProjectInfo.contract_start_date"
                                value-format="yyyy-MM-dd"
                                placeholder="请选择合同开工日期"></el-date-picker>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="建设单位负责人"
                            prop="build_leader_name">
                <el-input v-model="industryProjectInfo.build_leader_name"
                          placeholder="请输入建设单位负责人"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="合同竣工日期"
                            prop="contract_end_date">
                <el-date-picker v-model="industryProjectInfo.contract_end_date"
                                value-format="yyyy-MM-dd"
                                placeholder="请选择合同竣工日期"></el-date-picker>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="建设单位负责人身份证号"
                            prop="build_leader_card_no">
                <el-input v-model="industryProjectInfo.build_leader_card_no"
                          placeholder="请输入建设单位负责人身份证号"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="合同工期（天）"
                            prop="contract_days">
                <el-input v-model="industryProjectInfo.contract_days"
                          placeholder="请选择合同工期"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="建设单位负责人手机号"
                            prop="build_leader_phone">
                <el-input v-model="industryProjectInfo.build_leader_phone"
                          placeholder="请输入建设单位负责人手机号"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="计划开工日期"
                            prop="plan_start_date">
                <el-date-picker v-model="industryProjectInfo.plan_start_date"
                                value-format="yyyy-MM-dd"
                                placeholder="请选择计划开工日期"></el-date-picker>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="建设单位法人"
                            prop="build_legal_person">
                <el-input v-model="industryProjectInfo.build_legal_person"
                          placeholder="请输入建设单位法人"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="计划竣工日期"
                            prop="plan_end_date">
                <el-date-picker v-model="industryProjectInfo.plan_end_date"
                                value-format="yyyy-MM-dd"
                                placeholder="请选择计划竣工日期"></el-date-picker>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="建设单位法人身份证"
                            prop="build_legal_card_no">
                <el-input v-model="industryProjectInfo.build_legal_card_no"
                          placeholder="请输入建设单位法人身份证"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="项目状态"
                            prop="project_status">
                <el-select v-model="industryProjectInfo.project_status"
                           placeholder="请选择项目状态">
                  <el-option v-for="item in projectStateCode"
                             :key="item.code_id"
                             :label="item.name"
                             :value="item.value">
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="建设单位联系人"
                            prop="build_legal_name">
                <el-input v-model="industryProjectInfo.build_legal_name"
                          placeholder="请输入建设单位联系人"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="工程用途"
                            prop="project_usage">
                <el-select v-model="industryProjectInfo.project_usage"
                           placeholder="请选择工程用途">
                  <el-option v-for="item in projectUseageCode"
                             :key="item.code_id"
                             :label="item.name"
                             :value="item.value">
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="建设单位联系人电话"
                            prop="build_legal_phone">
                <el-input v-model="industryProjectInfo.build_legal_phone"
                          placeholder="请输入建设单位联系人电话"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="结构类型"
                            prop="struct_type">
                <el-select v-model="industryProjectInfo.struct_type"
                           placeholder="请选择结构类型">
                  <el-option v-for="item in constructTypeCode"
                             :key="item.code_id"
                             :label="item.name"
                             :value="item.value">
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <!-- <el-col :span="12">
              <el-form-item label="预制率"
                            prop="prefabrication_rate">
                <el-input v-model="industryProjectInfo.prefabrication_rate"
                          placeholder="请输入预制率"></el-input>
              </el-form-item>
            </el-col> -->
            <el-col :span="12">
              <el-form-item label="装配施工部位"
                            prop="assembly_con_position">
                <el-input v-model="industryProjectInfo.assembly_con_position"
                          placeholder="请输入装配施工部位"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="装配率"
                            prop="assembly_rate">
                <el-input v-model="industryProjectInfo.assembly_rate"
                          placeholder="请输入装配率"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="是否全装修"
                            prop="is_full_trim">
                <el-select v-model="industryProjectInfo.is_full_trim"
                           placeholder="请选择是否全装修">
                  <el-option label="是"
                             value="1"></el-option>
                  <el-option label="否"
                             value="0"></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="层数"
                            prop="floor_num">
                <el-input v-model="industryProjectInfo.floor_num"
                          placeholder="请输入层数"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="全装修面积（平方米）"
                            prop="full_trim_area">
                <el-input v-model="industryProjectInfo.full_trim_area"
                          placeholder="请输入全装修面积"></el-input>
              </el-form-item>
            </el-col>

            <el-col :span="12">
              <el-form-item label="装配式面积（平方米）"
                            prop="assembly_area">
                <el-input v-model="industryProjectInfo.assembly_area"
                          placeholder="请输入装配式面积"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="构件部品厂商"
                            prop="component_manufacturer">
                <div class="comp-factory-list">
                  <div class="factory-item"
                       v-for="(item,index) in industryProjectInfo.component_manufacturer"
                       :key="index">
                    <el-input v-model="item.name"
                              placeholder="请输入构件部品厂商"></el-input>
                    <i @click="addManufacturer"
                       v-if="index===0 && status!=='detail'"
                       class="icon el-icon-circle-plus"></i>
                    <i @click="deleteManufacturer(index)"
                       v-if="index!==0 && status!=='detail'"
                       class="icon el-icon-remove"></i>
                  </div>

                </div>

              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="项目概况"
                            prop="remark">
                <el-input type="textarea"
                          v-model="industryProjectInfo.remark"
                          placeholder="请输入项目概况"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item label="装配率计算书">
                <el-button type="primary"
                           @click="addFileUpload">添加</el-button>
                <div v-for="(item,index) in industryProjectInfo.assembly_rate_cal_file"
                     :key="item.url"
                     class="file-list">
                  <p class="ellipsis"
                     @click="donwloadFile(item)">{{item.file_name}}</p>
                  <el-upload action=""
                             :ref="'fileUpload'+index"
                             :show-file-list="false"
                             :limit="1"
                             :on-success="uploadPictureSuccess(index)"
                             :http-request="file=>{uploadPicture(file,item,`fileUpload${index}`)}">
                    <el-button type="primary"
                               size="small">点击上传
                    </el-button>
                  </el-upload>
                </div>
              </el-form-item>
            </el-col>
          </el-form>
        </div>
        <div v-if="status!=='detail'"
             class="back">
          <!-- 普通项目保存 -->
          <el-button @click="editProject"
                     v-if="projectInfoForm.is_indust_project==='2'"
                     type="primary">保存</el-button>
          <!-- 1369项目保存 -->
          <el-button v-if="projectInfoForm.is_indust_project==='1' && projectStep===2"
                     type="primary"
                     @click="prevStep">上一步</el-button>
          <el-button @click="editExtProject"
                     v-if="projectInfoForm.is_indust_project==='1' && projectStep===2"
                     type="primary">保存</el-button>
          <el-button @click="nextStep('edit')"
                     type="primary"
                     v-if="projectInfoForm.is_indust_project==='1' && projectStep===1">下一步</el-button>
          <el-button @click="onBack">取消</el-button>
        </div>
        <div v-if="status==='detail'"
             class="back">
          <el-button @click="nextStep('detail')"
                     type="primary"
                     v-if="projectInfoForm.is_indust_project==='1' && projectStep===1">下一步</el-button>
          <el-button @click="onBack">返回</el-button>
        </div>
      </el-col>
    </el-row>
    <Map :mapLngLat.sync="projectInfoForm"
         :dialogVisible.sync="mapDialogVisible"></Map>
    <NewMap :mapLngLat.sync="projectInfoForm"
            :dialogVisible.sync="newmapDialogVisible"></NewMap>

    <!-- 选择项目部弹框 -->
    <el-dialog title="选择项目部"
               :visible.sync="organizationDialogVisible"
               width="40%">
      <el-row>
        <el-col :span='12'>
          <OrganizationTree :curMenu.sync="selectedNode"
                            :deptSort="2"
                            :selectProject='true'></OrganizationTree>
        </el-col>
      </el-row>
      <span slot="footer"
            class="dialog-footer">
        <el-button @click="organizationDialogVisible = false">取 消</el-button>
        <el-button type="primary"
                   @click="selectDept">确 定</el-button>
      </span>
    </el-dialog>

    <el-dialog title="绑定项目"
               top="5vh"
               width="80%"
               :visible.sync="bindProjectDialogVisible">
      <ConstructProjectList pageType='component'
                            :choosedRow.sync="choosedRow"></ConstructProjectList>
      <div slot="footer">
        <el-button @click="bindProjectDialogVisible = false">取 消</el-button>
        <el-button type="primary"
                   @click="bindProject">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import QRCode from 'qrcodejs2';//二维码
import LocationSelect from '@/components/LocationSelect/LocationSelect'
import Map from '@/components/Map/Map'
import NewMap from '@/components/Map/NewMap'
import { UploadFileApi, userPermissionApi } from '@/services/UserPermission'
import { ProjectListApi } from '@/services/ProjectCenter'
import { standardCodeApi } from '@/services/StandardCode'
import OrganizationTree from '@/components/OrganizationTree/OrganizationTree'
import { organizationApi } from '@/services/CompanySetting'
import JobUserList from '@/pages/ConfigCenter/CompanySetting/components/JobUserList'
import ConstructProjectList from '@/pages/ProjectCenter/ConstructProjectList'
import { util } from "@/helper";
export default {
  data () {
    var checkProName = (rule, value, callback) => {
      if (value === '') {
        callback(new Error('请输入项目名称'))
      } else if ((/^[\s　]|[ ]$/gi).test(value)) {
        callback(new Error('项目名称首尾不能含有空格！'))
      } else {
        callback()
      }
    }
    var checkProNickName = (rule, value, callback) => {
      if (value === '') {
        callback(new Error('请输入项目简称'))
      } else if ((/^[\s　]|[ ]$/gi).test(value)) {
        callback(new Error('项目简称首尾不能含有空格！'))
      } else {
        callback()
      }
    }
    // 验证身份证
    var checkCreditCode = (rule, value, callback) => {
      if (value === '') {
        callback()
      } else if (!/^[1-9]\d{5}(18|19|20)\d{2}((0[1-9])|(1[0-2]))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/.test(value)) {
        callback(new Error('请输入正确的身份证'))
      } else {
        callback()
      }
    }
    return {
      isIndustryPro: false,//默认为非工业化项目
      requestparams: {
        node_type: '',
        id: ''
      },
      qrcodeUrl: '',
      isSyncProjectId: '',
      isSync: 0,//0:不同步  1：同步
      qrCode: '', // 二维码
      selectedNode: {},
      organizationDialogVisible: false,
      deptArr: [], // 存放部门数组
      selectLeaderNode: {}, // 项目经理对象
      selectLeaderDialogVisible: false,
      tableRowData: {},
      managerArr: [],
      // 获取人员列表请求参数
      getJobUserListParam: {
        org_no: '',
        dept_no: '',
        job_id: '',
        node_type: '',
        user_name: '',
        is_page: 1,
        page: 1,
        page_size: 10
      },
      projectInfoForm: {
        is_sync: 0,//0：不同步； 1：同步
        project_code: '',//项目代码
        is_indust_project: '0',
        project_name: '',
        nick_name: '',
        business_type: '',
        business_type_list: [],
        major_type: '',
        building_type: '',
        license_number: '',
        assembly_rate: '',
        leader_name: '',
        // leader_phone: '',
        // leader_id: '',
        dept_no: '',
        address: '',
        lon: '',
        lat: '',
        lonlat: '',
        floorage: '',
        status: '',
        contract_total: '',
        sign_time: '',
        application: '',
        img: '',
        img_url: '',
        project_attr: {},
        count: 0,
        project_license_no: '',
        jt_project_id: 0,
        jt_project_name: '',
        province: '',
        province_no: '',
        city: '',
        city_no: '',
        area: '',
        area_no: ''
      },
      // 根据业务身份和专业类型动态获取需要渲染的表单
      dynamicForm: [],
      rules: {
        project_code: [
          { required: true, message: '项目代码不能为空', trigger: 'blur' }
        ],
        is_indust_project: [
          { required: true, message: '请选择是否工业化项目', trigger: 'blur' }
        ],
        project_name: [
          { required: true, validator: checkProName, trigger: 'blur' }
        ],
        nick_name: [
          { required: true, validator: checkProNickName, trigger: 'blur' }
        ],
        business_type: [
          { required: true, message: '请选择业务身份', trigger: 'change' }
        ],

        major_type: [
          { required: true, message: '请选择专业类型', trigger: 'change' }
        ],
        building_type: [
          { required: true, message: '请选择建筑类型', trigger: 'change' }
        ],
        floorage: [
          { required: true, message: '请输入建筑面积', trigger: 'blur' }
        ],
        address: [
          { required: true, message: '请输入详细地址', trigger: 'blur' }
        ],
        license_number: [
          { required: true, message: '请输入项目许可编号', trigger: 'blur' }
        ],
        assembly_rate: [
          { required: true, message: '请输入装配率', trigger: 'blur' }
        ],
        status: [
          { required: true, message: '请选择项目状态', trigger: 'blur' }
        ],
        contract_total: [
          { required: true, message: '请输入合同总额', trigger: 'blur' }
        ],
        sign_time: [
          { required: true, message: '请选择签订时间', trigger: 'blur' }
        ],
        application: [
          { required: true, message: '请输入技术应用', trigger: 'blur' }
        ],
        lonlat: [
          { required: true, message: '请选择地图位置', trigger: 'change' }
        ],
        leader_name: [
          { required: true, message: '请输入项目经理', trigger: 'blur' }
        ],
        dept_no: [
          { required: true, message: '请选择项目部', trigger: 'change' }
        ],
        city_no: [
          { required: true, message: '请选择项目地址', trigger: 'change' }
        ],

      },
      //业务身份标准码列表
      businessTypeList: [],
      // 建筑类型标准码列表
      buildingTypeList: [],
      // 专业类型标准码列表
      majorTypeList: [],
      // 项目状态标准码列表
      projectStatusList: [
        { name: '未完成', value: '1' },
        { name: '已完成', value: '2' }
      ],
      buildUnitArr: [
        {
          build_unit: ''
        }
      ],
      imageUrl: '',
      // 地图选择框是否可见
      mapDialogVisible: false,
      newmapDialogVisible: false,
      // 处于新增或修改状态
      projectStatus: 'update',
      projectInfoDetail: {},
      projectInfoDetailData: [],
      // 绑定外部项目弹框是否可见
      bindProjectDialogVisible: false,
      // 绑定外部项目选择的行
      choosedRow: {},
      // 新建项目步骤
      projectStep: 1,
      // 工业化项目信息
      industryProjectInfo: {
        project_ext_id: '',
        project_license_no: '',
        project_name: '',
        construct_nature: '',
        project_type: '',
        invest_nature: '',
        approval_auth_level: '',
        totall_cost: '',
        total_invest: '',
        street: '',
        street_no: '',
        quality_sup_station: '',
        quality_safe_sup_no: '',
        address: '',
        project_station: '',
        total_build_area: '',
        lon: '',
        lat: '',
        len: '',
        width: '',
        contract_price: '',
        contract_start_date: '',
        contract_end_date: '',
        contract_days: '',
        plan_start_date: '',
        plan_end_date: '',
        project_status: '',
        project_usage: '',
        is_important: '',
        video_install_status: '',
        build_company: '',
        build_credit_code: '',
        build_leader_name: '',
        build_leader_card_no: '',
        build_leader_phone: '',
        build_legal_person: '',
        build_legal_card_no: '',
        build_legal_name: '',
        build_legal_phone: '',
        is_indust_project: '',
        struct_type: '',
        prefabrication_rate: '',
        assembly_con_position: '',
        assembly_rate: '',
        is_full_trim: '',
        floor_num: '',
        full_trim_area: '',
        component_manufacturer: [{ name: '' }],
        assembly_area: '',
        remark: '',
        assembly_rate_cal_file: []
      },
      extFormRules: {
        project_license_no: [
          { required: true, message: '请输入项目施工许可证', trigger: 'blur' },
          { max: 50, message: '最多输入50字符', trigger: 'blur' }
        ],
        project_name: [
          { required: true, message: '请输入施工工程名称', trigger: 'blur' },
          { max: 50, message: '最多输入50字符', trigger: 'blur' }
        ],
        construct_nature: [
          { required: true, message: '请选择建设性质', trigger: '' }
        ],
        project_type: [
          { required: true, message: '请选择项目类型', trigger: '' }
        ],
        invest_nature: [
          { required: true, message: '请选择项目投资性质', trigger: '' }
        ],
        approval_auth_level: [
          { required: true, message: '请选择审批机构级别', trigger: '' }
        ],
        street_no: [
          { required: true, message: '请选择街道', trigger: '' }
        ],
        quality_sup_station: [
          { required: true, message: '请输入质监站', trigger: 'blur' },
          { max: 50, message: '最多输入50字符', trigger: 'blur' }
        ],
        address: [
          { required: true, message: '请输入建设地点', trigger: 'blur' },
          { max: 50, message: '最多输入50字符', trigger: 'blur' }
        ],
        project_station: [
          { required: true, message: '请输入项目位置', trigger: 'blur' },
          { max: 50, message: '最多输入50字符', trigger: 'blur' }
        ],
        total_build_area: [
          { required: true, message: '请输入总建筑面积', trigger: 'blur' }
        ],
        is_important: [
          { required: true, message: '请选择是否重点项目', trigger: '' }
        ],
        video_install_status: [
          { required: true, message: '请选择视频安装状态', trigger: '' }
        ],
        build_company: [
          { required: true, message: '请输入建设单位名称', trigger: '' },
          { max: 50, message: '最多输入50字符', trigger: 'blur' }
        ],
        contract_price: [
          { required: true, message: '请输入合同价格', trigger: 'blur' }
        ],
        build_credit_code: [
          { required: true, message: '请输入建设单位社会统一信用代码', trigger: 'blur' }
        ],
        contract_start_date: [
          { required: true, message: '请选择合同开工日期', trigger: '' }
        ],
        contract_end_date: [
          { required: true, message: '请选择合同竣工日期', trigger: '' }
        ],
        contract_days: [
          { required: true, message: '请输入合同工期', trigger: 'blur' }
        ],
        plan_start_date: [
          { required: true, message: '请选择计划开工日期', trigger: '' }
        ],
        plan_end_date: [
          { required: true, message: '请选择计划竣工日期', trigger: '' }
        ],
        project_status: [
          { required: true, message: '请选择项目状态', trigger: '' }
        ],
        project_usage: [
          { required: true, message: '请选择工程用途', trigger: '' }
        ],
        struct_type: [
          { required: true, message: '请选择结构类型', trigger: '' }
        ],
        assembly_con_position: [
          { required: true, message: '请输入装配施工部位', trigger: 'blur' },
          { max: 200, message: '最多输入200字符', trigger: 'blur' }
        ],
        is_full_trim: [
          { required: true, message: '请选择是否全装修', trigger: '' }
        ],
        component_manufacturer: [
          { required: true, message: '请输入构件部品厂商', trigger: '' }
        ],
        remark: [
          { max: 1000, message: '最多输入1000字符', trigger: 'blur' }
        ],
        // build_leader_card_no: [
        //   { validator: checkCreditCode, trigger: 'blur' }
        // ],
        // build_legal_card_no: [
        //   { validator: checkCreditCode, trigger: 'blur' }
        // ]
      },
      // 项目类型标准码
      projectTypeCode: [],
      projectType: {},
      // 建设性质标准码
      buildingPropertyCode: [],
      buildingPropertyMap: {},
      // 项目投资性质标准码
      investPropertyCode: [],
      investPropertyMap: {},
      // 视频安装状态标准码
      videoInstallCode: [],
      videoInstallMap: {},
      // 审批机构级别标准码
      auditLevelCode: [],
      auditLevelMap: {},
      // 项目状态标准码
      projectStateCode: [],
      projectStateMap: {},
      // 工程用途标准码
      projectUseageCode: [],
      projectUseageMap: {},
      // 结构类型标准码
      constructTypeCode: [],
      constructTypeMap: {},
      // 街道列表
      streetList: [],
      streetMap: {},
      manufacturerList: []
    }
  },
  components: {
    LocationSelect,
    Map,
    NewMap,
    OrganizationTree,
    JobUserList,
    ConstructProjectList
  },
  props: {
    status: {
      type: String,
      default: () => {
        return 'create'
      }
    },
    callback: Function,
    projectId: {
      type: Number,
      default: () => {
        return 0
      }
    }
  },
  watch: {
    projectId (n, o) {
      console.log('iiiiin=', n)
    },
    projectInfoForm: {
      handler (newval, oldval) {

      },
      deep: true
    },
    status (newval, oldval) {

      this.projectStatus = newval
    },
    selectLeaderNode: {
      handler (newval, oldval) {
        let tempData = {}
        tempData.node_type = newval.node_type
        tempData.user_name = ''
        if (newval.node_type === '1') {
          tempData.org_no = newval.org_no
        } else if (newval.node_type === '2') {
          tempData.dept_no = newval.no
        } else if (newval.node_type === '3') {
          tempData.job_id = newval.id
        }
        this.getJobUserListParam = Object.assign(this.getJobUserListParam, tempData)

      },
      deep: true
    },
    selectedNode: {
      handler (newval, oldval) {
        console.log('adc====>', newval)
      },
      deep: true
    },
    // 表格点击行数据
    tableRowData: {
      handler (newval, oldval) {
        // console.log('row====>', newval)
      }
    }
  },
  methods: { //生成二维码
    bindQRCode () {
      ProjectListApi.getQrcode({
        data: this.requestparams
      }).then(res => {
        let a = document.createElement("a");
        let blob = new Blob([res], { type: 'image/png' })
        let url = URL.createObjectURL(blob)
        this.qrcodeUrl = url
      }, err => {
        console.log(err)
      }
      )
    },
    onDownQrcode () {//下载
      let a = document.createElement('a')
      a.href = this.qrcodeUrl;
      a.download = '二维码';
      a.click()
      this.$message({
        message: "正在进行下载保存",
        type: 'success'
      })
    },
    isSyncCurrentProCode (data) {//是否同步当前的项目代码的所有项目信息
      this.$confirm('该项目已存在,是否同步项目信息?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
        left: true
      }).then(async () => {
        this.isSync = 1;//1同步
        this.isSyncProjectId = data.project_id;
        await this.getProjectDetail(data.project_id);
        this.projectInfoForm.dept_no = '';//重置
        this.deptArr = [];//重置
        console.log('项目代码的项目信息=', data, 'deptArr=', this.deptArr, 'dept_no', this.projectInfoForm.dept_no)
      }).catch(() => {
        this.isSync = 0;//0不同步
        this.isSyncProjectId = '';
        this.projectInfoForm.is_sync = 0;//不同步
        this.$message({
          type: 'info',
          message: '已取消同步'
        });
      });
    },
    getIsExistProCode (proCode) {//项目代码是否存在
      ProjectListApi.getIsExistProCode({
        params: {
          project_code: proCode,//项目代码值
        }
      }).then((res) => {
        let data = res.data;//当前项目代码的项目信息
        let proCodeV = res.data.project_code;//项目代码值
        if (proCodeV && proCodeV == proCode) {//项目代码存在时
          this.isSyncCurrentProCode(data);//是否同步当前的项目代码
        }
        console.log('测试 项目代码res=', res, this.projectId)
      }).catch((error) => {
        console.log(error)
      })
    },
    onProCodeKeyUp (proCode) {//项目代码
      if (proCode != '') {
        this.getIsExistProCode(proCode);//判断当前项目代码是否已经存在
      }
      console.log('项目代码 proCode=', proCode)
    },
    onSyncZheLiIndPro () {//获取浙里建项目数据
      // this.$message.warning('开发中,敬请期待')
    },
    // 添加计算书上传容器
    addFileUpload () {
      if (this.industryProjectInfo.assembly_rate_cal_file.length < 5) {
        this.industryProjectInfo.assembly_rate_cal_file.push({ url: '' })
      } else {
        this.$message.warning('最多上传5条数据')
      }

    },
    // 装配率计算书上传成功事件
    uploadPictureSuccess (index) {

    },
    // 装配率计算书上传
    uploadPicture (file, item, ref) {
      let formData = new FormData();
      formData.append("module", "industry");
      formData.append("pic_file_apk", file.file);
      UploadFileApi.uploadFile({
        data: formData
      }).then(res => {
        this.$refs[ref][0].clearFiles()
        if (res.data) {
          this.$message.success("上传成功");
          item.url = res.data.file_path
          let str = res.data.file_path.split('industry/industry/')[1] || ''
          let name = str.split('/')[1]
          item.file_name = name
        }
      }, err => {
        this.$refs[ref][0].clearFiles()
      });
    },
    // 下载装配率计算书
    donwloadFile (item) {
      window.open(item.url)
    },
    // 删除构件厂商
    deleteManufacturer (index) {
      this.industryProjectInfo.component_manufacturer.splice(index, 1)
    },
    // 添加构件厂商
    addManufacturer () {
      this.industryProjectInfo.component_manufacturer.push({ name: '' })
    },
    chooseStreet () {
      let street = this.streetMap[this.industryProjectInfo.street_no]
      this.industryProjectInfo.street = street.street
    },
    // 工业化项目保存
    editExtProject () {
      this.$refs.extForm.validate((valid) => {
        if (valid) {
          this.industryProjectInfo.project_id = this.projectInfoForm.project_id
          this.industryProjectInfo.province = this.projectInfoForm.province
          this.industryProjectInfo.province_no = this.projectInfoForm.province_no
          this.industryProjectInfo.city = this.projectInfoForm.city
          this.industryProjectInfo.city_no = this.projectInfoForm.city_no
          this.industryProjectInfo.area = this.projectInfoForm.area
          this.industryProjectInfo.area_no = this.projectInfoForm.area_no
          if (this.isSync == 1) {
            this.$delete(this.industryProjectInfo, 'project_ext_id')
          }
          ProjectListApi.projectExtSave({
            data: this.industryProjectInfo
          }).then(res => {
            if (res.code === 0) {
              this.$message.success('编辑工业化项目成功')
              this.$router.push('/ProjectList')
            }
          })
        }
      })
    },
    // 上一步
    prevStep () {
      this.projectStep = 1
    },
    // 下一步
    nextStep (type) {
      if (type === 'edit') {//编辑
        this.$refs.projectInfoForm.validate((valid) => {
          if (valid) {
            if (this.projectStatus === 'create' && this.projectId == 0) {//新增
              ProjectListApi.createProject({
                data: this.projectInfoForm
              }).then(res => {
                if (res.code === 0) {
                  this.$message.success('新增项目成功');
                  this.projectStep = 2;
                  this.projectInfoForm.project_id = res.data.project_id;
                  this.industryProjectInfo.component_manufacturer = [{ name: '' }];
                  if (this.isSync == 1) {
                    this.projectInfoForm.id = this.isSyncProjectId;
                    this.getIndustryProjectDetail();//第二次的详情
                  }
                }
              })
            } else {//编辑
              this.projectInfoForm.id = this.projectInfoForm.project_id
              ProjectListApi.updateProject({
                data: this.projectInfoForm
              }).then(res => {
                if (res.code === 0) {
                  this.$message.success('修改项目成功')
                  this.getIndustryProjectDetail()
                }
              }, err => {
                console.log(err)
              })
            }
            this.getStreetList()
          }
        })
      } else {
        this.getIndustryProjectDetail()
      }

    },
    // 获取工业化项目详情
    getIndustryProjectDetail () {
      ProjectListApi.projectExtDetail({
        params: {
          project_id: this.isSync == 1 ? this.isSyncProjectId : this.projectInfoForm.project_id
        }
      }).then(res => {
        if (res.code === 0) {
          this.industryProjectInfo = Object.assign(this.industryProjectInfo, res.data)
          if (this.industryProjectInfo.component_manufacturer.length <= 0) {
            this.industryProjectInfo.component_manufacturer = [{ name: '' }]
          }
          this.industryProjectInfo.assembly_rate_cal_file.map((item) => {
            // 分割文件地址，得到文件名称
            if (item.url) {
              let str = item.url.split('industry/industry/')[1] || ''
              let name = str.split('/')[1]
              item.file_name = name
            }

          })
          this.projectStep = 2
        }
      })
    },
    // 切换是否工业化项目
    toggleIsPlat (value) {

    },
    // 获取街道列表
    getStreetList () {
      ProjectListApi.getStreetList({
        data: {
          area_type: '4',
          area_no: this.projectInfoForm.area_no
        }
      }).then(res => {
        if (res.code === 0) {
          this.streetList = res.data
          this.streetList.map((item) => {
            this.streetMap[item.street_no] = item
          })
        }
      })
    },
    downLoad () {//下载项目二维码
      let myCanvas = document.getElementById('qrcode').getElementsByTagName('canvas');
      let a = document.createElement('a')
      a.href = myCanvas[0].toDataURL('image/png');
      a.download = this.projectInfoForm.project_name + '项目二维码';
      a.click()
      this.$message({
        message: "正在进行下载保存",
        type: 'success'
      })
    },
    getQrCode () {//生成二维码
      let objVal = { project_id: this.$route.query.project_id };
      let qrcode = new QRCode('qrcode', {
        width: 132,
        height: 132,
        text: JSON.stringify(objVal), // 二维码地址
        colorDark: "#000",
        colorLight: "#fff",
      });
      qrcode._el.title = "";//隐藏提示
    },
    // 绑定建投项目
    bindOuterProjectDialog () {
      this.bindProjectDialogVisible = true
    },
    bindProject () {
      let keys = Object.keys(this.choosedRow)
      if (keys.length === 0) {
        this.$message.warning('请选择项目')
        return
      }
      let res = util.getLocationNo(this.choosedRow.province, this.choosedRow.city, this.choosedRow.area)
      this.choosedRow.province_no = res.provinceNo
      this.choosedRow.city_no = res.cityNo
      this.choosedRow.area_no = res.areaNo
      this.projectInfoForm = Object.assign(this.projectInfoForm, this.choosedRow)
      this.projectInfoForm.address = this.choosedRow.comm_addr
      this.projectInfoForm.out_project_id = this.choosedRow.code
      this.projectInfoForm.outer_service = 'jt'
      this.bindProjectDialogVisible = false
    },
    // 打开选择项目弹窗
    openManageDialog () {
      this.organizationDialogVisible = true
    },
    // 处理传入的数据，因为后端都是children_list，需要手动赋值一个children字段
    handelData (arr) {
      if (Object.prototype.toString.call(arr) === '[object Array]') {
        arr.map((item) => {
          if (item.children_list) {
            item.children = item.children_list
            this.handelData(item.children_list)
          } else if (item.childrens) {
            item.children = item.childrens
            this.handelData(item.childrens)
          }
          // console.log('this.projectInfoForm.dept_no', this.projectInfoDetail)
          if (item.no === this.projectInfoDetail.dept_no) {
            this.deptArr.length = 0
            this.deptArr.push({
              key: item.no,
              value: item.no,
              label: item.name
            })
          }
        })
        return arr
      }
    },
    // 获取组织树数据
    getOrgTree () {
      return organizationApi.getOrgTree({
        data: {
          node_type: '2'
        }
      }).then(res => {
        console.log(res, 'get org tree')
        let data = res.data
        this.projectInfoDetailData = data
        // console.log(data, 'handle data')
        if (this.projectId) {
          this.getDeptNo()
        }

        this.$store.dispatch('setOrgainzationTree', data)
        window.localStorage.setItem('platformOrganizationTree', JSON.stringify(data))
      }, err => {
        console.log(err)
      })
    },
    getDeptNo () {
      ProjectListApi.getProjectDetail({
        data: {
          id: this.projectId
        }
      }).then(res => {
        if (res.code === 0) {
          console.log('测试-详情-res=', res)
          let projectInfo = res.data.project_info
          this.projectInfoDetail = projectInfo
          this.handelData(this.projectInfoDetailData)
        }
      }, err => {
        console.log(err)
      })
    },
    // 选择项目部
    selectDept () {
      if (this.selectedNode.node_type !== '2' || this.selectedNode.dept_type === '1') {
        this.$message.error('请选择项目部')
      } else {
        this.deptArr.length = 0
        this.deptArr.push({
          key: this.selectedNode.no,
          value: this.selectedNode.no,
          label: this.selectedNode.name
        })
        // this.projectInfoForm.dept_no = this.selectedNode.id
        this.projectInfoForm.dept_no = this.selectedNode.no
        this.projectInfoForm.org_no = this.selectedNode.org_no
        this.organizationDialogVisible = false
        // console.log('deptArr', this.selectedNode, this.deptArr)
        // // 需要赋值的输入框
        // let targetInput = this.companyInfo[this.selectDeptType].data[this.selectDeptIndex].dept_info
        // targetInput.dept_id = this.selectedNode.id
        // targetInput.dept_name = this.selectedNode.name
        // this.organizationDialogVisible = false
      }
    },
    // 上传项目图片
    uploadProjectImg (file) {
      let formData = new FormData()
      formData.append('module', 'industry')
      formData.append('pic_file_apk', file.file)
      UploadFileApi.uploadFile({
        data: formData
      }).then(res => {
        if (res.data) {
          this.$message.success('上传成功')
          this.projectInfoForm.img = res.data.file_name
          this.projectInfoForm.img_url = res.data.file_path
        }
      })
    },
    // 根据接口返回的表单列表判断是否需要展示该表单
    isShowFormItem (name) {
      let flag = this.dynamicForm.includes(name)
      return flag
    },
    // 返回触发后执行事件
    onBack () {
      this.$router.push({ path: '/projectList' })
    },

    // 图片上传功能
    handleAvatarSuccess (res, file) {
      this.imageUrl = URL.createObjectURL(file.raw)
    },
    // 图片上传前的钩子
    beforeAvatarUpload (file) {

    },
    // 选择具体经纬度
    selectMap () {
      this.mapDialogVisible = true
    },
    selectNewMap () {
      this.newmapDialogVisible = true
    },
    // 判断是新增或是编辑
    editProject () {
      // this.$emit('update:step', 2)
      this.$refs.projectInfoForm.validate((valid) => {
        if (valid) {
          if (this.projectStatus === 'create') {
            if (this.projectInfoForm.province != '' && this.projectInfoForm.city != '' && this.projectInfoForm.area != '') {
              this.createProject()
            } else {
              this.$message.error('请选择省市区')
            }
          } else if (this.projectStatus === 'update') {
            this.updateProject()
          }
        }
      })
    },
    // 新增项目
    createProject () {
      ProjectListApi.createProject({
        data: {
          project_code: this.projectInfoForm.project_code,//项目代码
          project_name: this.projectInfoForm.project_name,
          nick_name: this.projectInfoForm.nick_name,
          business_type: this.projectInfoForm.business_type,
          building_type: this.projectInfoForm.building_type,
          province: this.projectInfoForm.province,
          province_no: this.projectInfoForm.province_no,
          city: this.projectInfoForm.city,
          city_no: this.projectInfoForm.city_no,
          area: this.projectInfoForm.area,
          area_no: this.projectInfoForm.area_no,
          address: this.projectInfoForm.address,
          lon: this.projectInfoForm.lon,
          lat: this.projectInfoForm.lat,
          img: this.projectInfoForm.img,
          // leader_id: this.projectInfoForm.leader_id,
          leader_name: this.projectInfoForm.leader_name,
          // leader_phone: this.projectInfoForm.leader_phone,
          dept_no: this.projectInfoForm.dept_no,
          org_no: this.projectInfoForm.org_no,
          out_project_id: this.projectInfoForm.out_project_id,
          outer_service: 'jt'
        }
      }).then(res => {

        if (res.code === 0) {
          this.$message.success('新建项目成功')
          window.localStorage.setItem('deptArr', JSON.stringify(this.deptArr))
          this.$router.push('/ProjectList')
          // this.$emit('callback', { step: 2, id: res.data.project_id })
        }
      }, err => {
        console.log(err)
      })
    },
    // 编辑项目
    updateProject () {
      this.projectInfoForm.id = this.projectInfoForm.project_id
      ProjectListApi.updateProject({
        data: this.projectInfoForm
      }).then(res => {
        if (res.code === 0) {
          this.$message.success('修改项目成功')
          window.localStorage.setItem('deptArr', JSON.stringify(this.deptArr))
          this.$router.push('/ProjectList')
          // this.$emit('callback', { step: 2, id: this.projectId })
        }
      }, err => {
        console.log(err)
      })
    },
    // 选择业务身份
    chooseBusinessType () {
      if (this.projectInfoForm.business_type_list.length > 0) {
        // this.projectStatusList = this.projectStatusList.filter((item) => {
        //   return item.content1 === '4'
        // })
      }
      // console.log('this.projectInfoForm.business_type', this.projectInfoForm.business_type, this.projectInfoForm.business_type_list)
      // this.projectInfoForm.business_type = this.projectInfoForm.business_type_list.join(',')

      // this.isCompleteBasicInfo()
    },
    // 选择专业类型
    chooseMajorType () {
      // this.isCompleteBasicInfo()
    },
    // 判断是否完善了业务身份、专业类型基本信息，如果已完成则调用获取项目配置接口，获取需要渲染的表单字段
    // isCompleteBasicInfo () {
    //   console.log(this.projectStatus, 'status')
    //   if (this.projectInfoForm.business_type_list.length > 0 && this.projectInfoForm.major_type && this.projectStatus === 'create') {
    //     // 判断选择的业务身份组合是否合法
    //     let len = this.projectInfoForm.business_type_list.length
    //     console.log(len, len !== 1, len !== 3, 'len')
    //     if (len !== 1 && len !== 3) {
    //       this.$message.error('当前业务组合不支持，请重新选择')
    //     } else {
    //       ProjectListApi.getProjectConfig({
    //         params: {
    //           bussi_type: this.projectInfoForm.business_type,
    //           major_id: this.projectInfoForm.major_type
    //         }
    //       }).then(res => {
    //         console.log(res, 'get project config')
    //         if (res.code === 0) {
    //           this.dynamicForm = res.data.data
    //         }
    //       })
    //     }
    //   }
    // },
    // 获取需要显示的表单列表
    getDynamicFormItem () {
      this.dynamicForm = []
    },
    // 获取业务身份标准码
    getBusinessTypeCode () {
      return standardCodeApi.getStandardCodeData({
        data: {
          code_type: 'businessType'
        }
      }).then(res => {
        if (res.code === 0 && res.data.list) {
          this.businessTypeList = res.data.list
          window.localStorage.setItem('platformBusinessTypeCode', JSON.stringify(this.businessTypeList))
        }
      }, err => {
        console.log(err)
      })
    },
    // 获取建筑类型标准码
    getBuildingTypeCode () {
      return standardCodeApi.getStandardCodeData({
        data: {
          code_type: 'buildingType'
        }
      }).then(res => {
        if (res.code === 0 && res.data.list) {
          this.buildingTypeList = res.data.list
          window.localStorage.setItem('platformBuildingTypeList', JSON.stringify(this.buildingTypeList))
        }
      }, err => {
        console.log(err)
      })
    },
    // 获取专业类型标准码
    getMajorTypeCode () {
      return standardCodeApi.getStandardCodeData({
        data: {
          code_type: 'major_type'
        }
      }).then(res => {
        if (res.code === 0 && res.data.list) {
          this.majorTypeList = res.data.list
          window.localStorage.setItem('platformMajorTypeList', JSON.stringify(this.majorTypeList))
        }
      }, err => {
        console.log(err)
      })
    },
    // 获取项目状态标准码
    getProjectStatusCode () {
      standardCodeApi.getStandardCodeData({
        data: {
          code_type: 'project_status'
        }
      }).then(res => {
        if (res.code === 0 && res.data.list) {
          this.projectStatusList = res.data.list
        }
      }, err => {
        console.log(err)
      })
    },
    getCurrentDepartTypeAndId (projectInfoDetailData) {//获取当前部门的id和类型  递归
      projectInfoDetailData.map((item) => {
        if (item.no == this.projectInfoForm.dept_no) {
          this.requestparams.node_type = item.node_type;
          this.requestparams.id = item.id;
        } else if (item.children) {//判断是否存在子级
          this.getCurrentDepartTypeAndId(item.children)//递归
        }
      });
    },
    // 获取项目详情 projectInfoDetailData
    getProjectDetail (proId) {
      return ProjectListApi.getProjectDetail({
        data: {
          id: proId,//项目主键值
        }
      }).then(res => {
        if (res.code === 0) {
          // 建筑类型，建筑面积等属性放在project_info中的project_attr中，需要手动迁移到project_info中
          // 由于project_attr中的建筑面积也使用了area作为属性名，需要手动修改为floorage
          let projectInfo = res.data.project_info
          if (projectInfo.project_attr) {
            projectInfo.project_attr.floorage = projectInfo.project_attr.area
            delete projectInfo.project_attr.area
          }
          // this.managerArr.length = 0
          // this.managerArr.push({
          //   key: projectInfo.leader_id,
          //   value: projectInfo.leader_id,
          //   label: projectInfo.leader_name
          // })
          this.deptArr = JSON.parse(window.localStorage.getItem('deptArr')) || [{ label: projectInfo.dept_name, value: projectInfo.dept_no }]
          // console.log('this.managerArr', this.managerArr, this.deptArr)
          // projectInfo.business_type_list = projectInfo.business_type.split(',')
          projectInfo.lonlat = projectInfo.lon + '-' + projectInfo.lat
          this.projectInfoForm = Object.assign(projectInfo, projectInfo.project_attr)
          let id = this.projectInfoForm.project_id.toString()
          this.getCurrentDepartTypeAndId(this.projectInfoDetailData);//获取当前部门的id和类型
          this.id = id
          this.bindQRCode()
          // this.projectInfoForm = res.data.project_info
          // this.$nextTick(() => {
          //   this.$refs.locationSelect.initProvinceData(this.projectInfoForm.area_no)
          // })          
          this.dynamicForm = res.data.project_config;
          this.projectInfoForm.is_sync = 1;//同步
        }
      }, err => {
        console.log(err)
      })
    },
    // 初始化标准码
    async initCode (code, codeData, codeMap, codeLocal) {
      let local = window.localStorage.getItem(codeLocal)

      if (local) {
        this[codeData] = JSON.parse(local)
        this[codeData].map((item) => {
          this[codeMap][item.value] = item
        })
      } else {
        await this.getStandardCode(code, codeData, codeMap, codeLocal)
      }
    },
    // 获取标准码
    getStandardCode (code, codeData, codeMap, codeLocal) {

      return standardCodeApi.getStandardCodeData({
        data: {
          code_type: code
        }
      }).then(res => {
        if (res.code === 0 && res.data.list) {
          this[codeData] = res.data.list;
          this[codeData].map((item) => {
            this[codeMap][item.value] = item
          })
          window.localStorage.setItem(codeLocal, JSON.stringify(res.data.list));
        }
      },
        err => {
          console.log(err);
        }
      );
    },
    judgeIndustryPro () {//判断是否为工业化项目
      let currentLocInfo = window.location.href;
      let industryPro = 'zljz.hibuilding.cn';//是否为当使用域名（http://zljz.hibuilding.cn/login
      if (currentLocInfo.indexOf(industryPro) != -1) {
        this.projectInfoForm.is_indust_project = '1';
        this.isIndustryPro = true;
      }
    }
  },

  async created () {//dom没渲染完成执行
    this.judgeIndustryPro();//判断是否为工业化项目
    await this.getOrgTree()
    let businessTypeCodeList = window.localStorage.getItem('platformBusinessTypeCode')
    let buildingTypeList = window.localStorage.getItem('platformBuildingTypeList')
    let majorTypeList = window.localStorage.getItem('platformMajorTypeList')
    this.projectStatus = this.status
    if (businessTypeCodeList) {
      this.businessTypeList = JSON.parse(businessTypeCodeList)
    } else {
      await this.getBusinessTypeCode()
    }
    if (buildingTypeList) {
      this.buildingTypeList = JSON.parse(buildingTypeList)
    } else {
      await this.getBuildingTypeCode()
    }
    if (majorTypeList) {
      this.majorTypeList = JSON.parse(majorTypeList)
    } else {
      // if (window.sessionStorage.getItem('access_token')) {
      if (window.localStorage.getItem('access_token')) {
        await this.getMajorTypeCode()
      }
    }
    // // 项目类型标准码
    this.initCode('project_type', 'projectTypeCode', 'projectType', 'projectType')
    // 建设性质标准码
    this.initCode('building_property', 'buildingPropertyCode', 'buildingPropertyMap', 'buildingPropertyMap')
    // 项目投资性质标准码
    this.initCode('invest_property', 'investPropertyCode', 'investPropertyMap', 'investPropertyMap')
    // 视频安装状态标准码
    this.initCode('video_install', 'videoInstallCode', 'videoInstallMap', 'videoInstallMap')
    // 审批机构级别标准码
    this.initCode('audit_level', 'auditLevelCode', 'auditLevelMap', 'auditLevelMap')
    // 项目状态标准码
    this.initCode('project_state', 'projectStateCode', 'projectStateMap', 'projectStateMap')
    // 工程用途标准码
    this.initCode('project_useage', 'projectUseageCode', 'projectUseageMap', 'projectUseageMap')
    // 结构类型标准码
    this.initCode('construct_type', 'constructTypeCode', 'constructTypeMap', 'constructTypeMap')
    if (this.projectId) {
      await this.getProjectDetail(this.projectId)
    }
  },
  mounted () {
    console.log('project_id=', this.$route.query.project_id)
    this.getQrCode()//生成二维码
  }
}
</script>

<style scoped lang='scss'>
.addProject-container {
  background: #fff;
  .pro-name-style {
    display: flex;
    flex-direction: row;
  }
  .bind-project {
    margin-left: 20px;
    // position: absolute;
    // left: 41%;
    // top: 0;
  }
  .project-title {
    padding: 20px;
    border-bottom: 1px solid #eff2f7;
    font-size: 16px;
    font-weight: 300;
  }
  .back {
    padding-left: 190px;
  }
  .pro-form {
    padding: 20px 0px;
    .normal-input {
      width: 40%;
    }
    .build-unit {
      margin-bottom: 20px;
    }
    .area-input {
      width: 13%;
    }
    /deep/ .avatar-uploader .el-upload {
      border: 1px dashed #d9d9d9;
      border-radius: 6px;
      cursor: pointer;
      position: relative;
      overflow: hidden;
    }
    .avatar-uploader .el-upload:hover {
      border-color: #409eff;
    }
    .avatar-uploader-icon {
      font-size: 28px;
      color: #8c939d;
      width: 178px;
      height: 178px;
      line-height: 178px;
      text-align: center;
    }
    .avatar {
      width: 178px;
      height: 178px;
      display: block;
    }
  }
  .div-qrcode {
    height: 145px;
    img {
      width: 145px;
      height: 145px;
    }
    .depart-down {
      height: 36px;
      position: absolute !important;
      left: 150px;
      bottom: 0px !important;
    }
  }
  .pro-code-style {
    display: flex;
    flex-direction: row;
    justify-content: flex-start;
    position: relative;
    .imm-down {
      height: 36px;
      position: absolute;
      left: 150px;
      bottom: 0px;
    }
  }
  .industry-project-info {
    .el-select,
    .el-input,
    .el-date-editor,
    .el-textarea {
      width: 90%;
    }
    .el-form {
      overflow: hidden;
    }
  }
  .factory-item {
    display: flex;
    align-items: center;
    margin-bottom: 10px;
    .el-input {
      width: 80%;
    }
    .icon {
      font-size: 30px;
      cursor: pointer;
    }
  }
  .file-list {
    display: flex;
    p {
      color: #1890ff;
      cursor: pointer;
      width: 240px;
    }
  }
}
</style>
